package com.bjc.gmall.service.impl;


import com.alibaba.dubbo.config.annotation.Reference;
import com.bjc.gmall.bean.UserAddress;
import com.bjc.gmall.service.OrderService;
import com.bjc.gmall.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @program: dubbo-study
 * @description:
 * @author: bjc
 * @create: 2020-07-19 12:20
 */
@Service
public class OrderServiceImpl implements OrderService {

    //@Autowired
    @Reference(loadbalance = "roundrobin") //这种需要注册中心 loadbalance = "roundrobin" 轮询机制
    //@Reference(url = "192.168.242.1:20882")  //@Reference(url = "192.168.242.1:20882") dubbo 直连这种可以不用注册中心
    UserService userService;

    @HystrixCommand(fallbackMethod = "hello")
    @Override
    public List<UserAddress> initOrder(String userId) {
        //1.查询用户地址
        System.out.println("用户id："+userId);
        List<UserAddress> addressList = userService.getUserAddressList(userId);
        for (UserAddress userAddress: addressList) {
            System.out.println(userAddress.getUserAddress());
        }
        return addressList;
    }

    public List<UserAddress> hello(String userId) {

        return Arrays.asList(new UserAddress(10, "测试地址", "1", "测试", "13552595XXXX", "Y"));
    }
}
